package 中国慕课作业3;

import java.util.ArrayList;
import java.util.Scanner;

public class home3 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        ArrayList<String> notes=new ArrayList<String>();
        String position,destination;
        int pstIndex, dstIndex;;
        String str=in.next();
        while(str.equals("###")!=true)
        {
            notes.add(str);
            str=in.next();
        }
        final int arrsize=notes.size();
        int[] distance=new int[arrsize*arrsize];
        for(int i=0;i<distance.length;i++)
        {
            distance[i]=in.nextInt();
        }
        position=in.next();
        destination=in.next();
        pstIndex= notes.indexOf(position);
        System.out.println("pstIndex="+pstIndex);
        dstIndex=notes.indexOf(destination);
        System.out.println("dstIndex="+dstIndex);
        System.out.println(distance[pstIndex*arrsize+dstIndex]);
        in.close();
    }
}
